package array
{
	import flash.utils.ByteArray;
	
	import data.Metadata;
	
	import tag.doABC2.CPool;
	
	import util.BytesUtil;

	public dynamic class MetadataArray extends Array
	{
		public function MetadataArray(...parameters)
		{
			super(parameters);
		}
		
		public function fill(bytes:ByteArray):void
		{
			var cp:CPool = App.cp;
			var count:uint = BytesUtil.readU30(bytes);
			if(count > 0){
				for(var i:int = 0;i < count; i++){
					var m:Metadata = new Metadata();
					this[i] = m;
					m.name = cp.cp_string[BytesUtil.readU30(bytes)];
					m.items = [];
					trace(m.name);
					var itemCount:int = BytesUtil.readU30(bytes);
					for(var j:int = 0; j < itemCount; j++){
						m.items[j] = {
							key:cp.cp_string[BytesUtil.readU30(bytes)],
							value:cp.cp_string[BytesUtil.readU30(bytes)]
						};
						trace(m.items[j].key + " : " + m.items[j].value);
					}
				}
			}
		}
	}
}